

package cn.shengchao.examstar.product.acl.adapters.repositories;

import cn.shengchao.examstar.product.acl.ports.repositories.ISpecificationTypeRepository;
import cn.shengchao.examstar.product.infrastructure.dao.SpecificationTypeDao;
import cn.shengchao.examstar.product.infrastructure.dao.TAppidSpecificationTypeDao;
import cn.shengchao.examstar.product.infrastructure.dao.po.TSpecificationType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SpecificationTypeRepository implements ISpecificationTypeRepository {

    @Autowired
    private SpecificationTypeDao specificationTypeDao;
    @Autowired
    private TAppidSpecificationTypeDao tAppidSpecificationTypeDao;
    @Override
    public void createSpecificationType(TSpecificationType specificationType) {
        specificationTypeDao.insert(specificationType);
    }
    @Override
    public List<TSpecificationType> getSpecificationTypeList(Long pid, String appid) {
        if(pid==null){
            return specificationTypeDao.selectList(new LambdaQueryWrapper<TSpecificationType>()
                    .eq(TSpecificationType::getStatus, "1")
                    .orderByAsc(TSpecificationType::getSort)
            );
        }
        if (pid == 0) {
            return specificationTypeDao.selectList(new LambdaQueryWrapper<TSpecificationType>()
                    .eq(TSpecificationType::getParentId, pid)
                    .eq(TSpecificationType::getStatus, "1")
                    .orderByAsc(TSpecificationType::getSort)
            );
        } else {
            return specificationTypeDao.selectList(new LambdaQueryWrapper<TSpecificationType>()
                    .eq(TSpecificationType::getParentId, pid)
                    .eq(TSpecificationType::getStatus, "1")
                    .orderByAsc(TSpecificationType::getSort)
            );
        }
    }


    @Override
    public List<TSpecificationType> getSpecificationTypesByIdList(List<Long> ids) {
            return specificationTypeDao.selectByIds(ids);
    }

    @Override
    public List<TSpecificationType> getSpecificationTypesByParentIdAndIdList(Long parentId, List<Long> ids) {
        return specificationTypeDao.selectList(new LambdaQueryWrapper<TSpecificationType>()
                .eq(TSpecificationType::getParentId, parentId)
                .in(TSpecificationType::getId, ids)
        );
    }

    @Override
    public int updateSpecificationTypeById(TSpecificationType specificationType) {
        return specificationTypeDao.updateById(specificationType);
    }
}
